package com.terrorism.sdk.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.terrorism.sdk.R;

/**
 * @since Friday, June 06, 2014
 * @author hoangcaomobile
 *
 */
public class CustomDialog {

	// dialog loadding
	private static Dialog dialogLoading;
	public static void vDialogLoadingShow(Context mContext, String message, boolean isCancelEnable) {
		dialogLoading = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
		dialogLoading.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
		dialogLoading.setContentView(R.layout.dialog_loadding);
		dialogLoading.setCancelable(isCancelEnable);
		dialogLoading.show();

		ImageView ivLoading = (ImageView) dialogLoading.findViewById(R.id.ivDialogLoading);
		ivLoading.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.rotate_spinner));

		TextView tvMessage = (TextView) dialogLoading.findViewById(R.id.tvDialogLoading);
		tvMessage.setText(message);

		if (isCancelEnable) {
			RelativeLayout layoutParent = (RelativeLayout) dialogLoading.findViewById(R.id.layoutDialogLoading);
			layoutParent.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialogLoading.dismiss();
				}
			});
		}
	}
	public static void vDialogLoadingShowProcessing(Context mContext, boolean isCancelEnable) {
		vDialogLoadingShow(mContext, mContext.getString(R.string.dialogMessageProcessing), isCancelEnable);
	}
	public static void vDialogLoadingDismiss() {
		dialogLoading.dismiss();
	}
	// --

	// dialog normal
	private static Dialog dialogNormal;
	public static void vDialogNormal(final Context mContext, String title, String body, boolean isCancelEnable, OnClickListener onClickOk) {
		dialogNormal = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
		dialogNormal.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
		dialogNormal.setContentView(R.layout.dialog_normal);
		dialogNormal.setCancelable(isCancelEnable);
		dialogNormal.show();

		TextView tvDialogTitle = (TextView) dialogNormal.findViewById(R.id.tvDialogTitle);
		TextView tvDialogBody = (TextView) dialogNormal.findViewById(R.id.tvDialogBody);
		Button btDialogCancel = (Button) dialogNormal.findViewById(R.id.btDialogCancel);
		Button btDialogOk = (Button) dialogNormal.findViewById(R.id.btDialogOk);

		tvDialogTitle.setText(title);	
		tvDialogBody.setText(body);
		btDialogCancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogNormal.dismiss();
			}
		});
		btDialogOk.setOnClickListener(onClickOk);

		if (isCancelEnable) {
			RelativeLayout layoutDialogParent = (RelativeLayout) dialogNormal.findViewById(R.id.layoutDialogParent);
			layoutDialogParent.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialogNormal.dismiss();
				}
			});
		}
	}
	public static void vDialogNormalDismiss() {
		dialogNormal.dismiss();
	}
	// --

	// dialog ok cancel
	private static Dialog dialogOkCancel;
	public static void vDialogOkCancel(final Context mContext, String title, String body, boolean isCancelEnable,
			boolean isFullScreen, OnClickListener onClickOk, OnClickListener onClickCancel) {
		if (isFullScreen) {
			dialogOkCancel = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		} else {
			dialogOkCancel = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
		}
		dialogOkCancel.setContentView(R.layout.dialog_normal);
		dialogOkCancel.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
		dialogOkCancel.setCancelable(isCancelEnable);
		dialogOkCancel.show();

		TextView tvDialogTitle = (TextView) dialogOkCancel.findViewById(R.id.tvDialogTitle);
		TextView tvDialogBody = (TextView) dialogOkCancel.findViewById(R.id.tvDialogBody);
		Button btDialogCancel = (Button) dialogOkCancel.findViewById(R.id.btDialogCancel);
		Button btDialogOk = (Button) dialogOkCancel.findViewById(R.id.btDialogOk);

		tvDialogTitle.setText(title);	
		tvDialogBody.setText(body);
		btDialogCancel.setOnClickListener(onClickCancel);
		btDialogOk.setOnClickListener(onClickOk);

		if (isCancelEnable) {
			RelativeLayout layoutDialogParent = (RelativeLayout) dialogOkCancel.findViewById(R.id.layoutDialogParent);
			layoutDialogParent.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialogOkCancel.dismiss();
				}
			});
		}
	}
	public static void vDialogOkCancelDismiss() {
		dialogOkCancel.dismiss();
	}
	// --

	// dialog confirm
	public static void vDialogConfirm(final Context mContext, String title, String body, boolean isCancelEnable) {
		final Dialog dialogConfirm = new Dialog(mContext, android.R.style.Theme_Translucent);
		dialogConfirm.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialogConfirm.setContentView(R.layout.dialog_confirm);
		dialogConfirm.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
		dialogConfirm.show();

		TextView tvDialogTitle = (TextView) dialogConfirm.findViewById(R.id.tvDialogTitle);
		TextView tvDialogBody = (TextView) dialogConfirm.findViewById(R.id.tvDialogBody);
		Button btDialogOk = (Button) dialogConfirm.findViewById(R.id.btDialogOk);

		tvDialogTitle.setText(title);	
		tvDialogBody.setText(body);
		btDialogOk.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogConfirm.dismiss();
			}
		});

		if (isCancelEnable) {
			RelativeLayout layoutDialogParent = (RelativeLayout) dialogConfirm.findViewById(R.id.layoutDialogParent);
			layoutDialogParent.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialogConfirm.dismiss();
				}
			});
		}
	}
	// --




}
